<?php
require_once "db.php";

$movie = db_escape($_POST['movieid']);

$content = "<div id='comments-list'>";
$comments_list_query_text = "SELECT comment_content, comment_date, accounts_idaccounts FROM comments WHERE movies_idmovies='$movie'";
$comments_list_query = db_query($comments_list_query_text);
if (mysqli_num_rows($comments_list_query)==0) {
		$content .= "There are no comments for this movie.";
}
else{
	while ($row = mysqli_fetch_assoc($comments_list_query)){
		$account_id = $row['accounts_idaccounts'];
		$account_query_text = "SELECT username FROM accounts WHERE idaccounts='$account_id'";
		$account_query = db_query($account_query_text);
		$account_row = mysqli_fetch_assoc($account_query);
		$content .= "<div class='comment-info'><div class='account-name-comment'>".$account_row['username']."</div>
				<div class='comment-date'>".$row['comment_date']."</div></div>
				<div class='read-comment-content'>".$row['comment_content']."</div>";
	}
}
$content .= "</div><div id='close-comments-list'><a href='#'>Close</a></div>";
echo $content;
